'use strict';

module.exports = app => {
  const mongoose = app.mongoose;
  const Schema = mongoose.Schema;
  const ObjectId = Schema.ObjectId;

  const ArticleSchema = new Schema({
    title: { type: String },
    remark: { type: String },//摘要
    content: { type: String },
    author: { type: String },
    openid: { type: String },
    banner: { type: String },
    avatarUrl: { type: String },  //作者头像
    tab: { type: String },//文章类型
    shoptoplvid: { type: String },   //三级商户id
    shopid: { type: String },   //三级商户id
    isZan: { type: Boolean },//用户是否点赞
    isMe: { type: Boolean, default: false },//文章是否是公司内文
    top: { type: Boolean, default: false }, // 置顶帖
    good: { type: Boolean, default: false }, // 精华帖
    lock: { type: Boolean, default: false }, // 被锁定主题
    wxcontect: { type: Boolean, default: false }, // 被锁定主题
    reply_count: { type: Number, default: 0 }, //回复数
    visit_count: { type: Number, default: 0 },//访问数
    collect_count: { type: Number, default: 0 },//点赞数
    create_at: { type: Date, default: Date.now },//创建时间
    update_at: { type: Date, default: Date.now },//更新时间
    last_reply: { type: ObjectId },//最后回复
    last_reply_at: { type: Date, default: Date.now },//最后回复时间
    deleted: { type: Boolean, default: false },//状态是否被删除
  });

  ArticleSchema.index({ create_at: -1 });
  ArticleSchema.index({ top: -1, last_reply_at: -1 });
  ArticleSchema.index({ author_id: 1, create_at: -1 });

  return mongoose.model('article', ArticleSchema);
};
